//
//  BaseModel.swift
//  Simple Switf Project
//
//  Created by 陈卫东 on 2017/1/19.
//  Copyright © 2017年 陈卫东. All rights reserved.
//

import UIKit
import HandyJSON

class BaseModel: HandyJSON {

    class func dictToModel<T: HandyJSON>(_ modelType: T.Type = T.self, dict: Any?) -> Any? {
        guard let _dict = dict else {
            return nil
        }

        if _dict is Array<Any> {
            var tempArray = Array<Any>()
            for dic in (_dict as! Array<Any>) {
                tempArray.append(self.dictToModel(modelType, dict: dic)!)
            }
            return tempArray
        } else if _dict is Dictionary<String, Any> {
            return modelType.deserialize(from: dict as? NSDictionary)
        } else if _dict is String {
            return modelType.deserialize(from: dict as? String)
        }
        return _dict
    }

    required init() {}
//    
//    required init(value: Any, schema: RLMSchema) {
//        fatalError("init(value:schema:) has not been implemented")
//    }


}
